﻿@{
                @using YiSha.Entity.Business;
                            @using YiSha.Util.Extension;
                                        @using YiSha.Enum.OrganizationManage; Layout = "~/Views/Shared/_FormWhite.cshtml"; }

<div class="wrapper animated fadeInRight">
    <form id="form" class="form-horizontal m">

        <div class="form-group">
            <label class="col-sm-3 control-label">店铺</label>
            <div class="col-sm-8">
                <div id="departmentId" col="DepartmentId"></div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">姓名<font class="red"> *</font></label>
            <div class="col-sm-8">
                <input id="realName" col="RealName" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">生日</label>
            <div class="col-sm-8">
                <input id="birthday" col="Birthday" class="form-control" placeholder="yyyy-MM-dd" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">身份</label>
            <div id="occupationValue" col="OccupationValue" class="col-sm-8"></div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">手机号码</label>
            <div class="col-sm-8">
                <input id="mobile" col="Mobile" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">性别</label>
            <div id="gender" col="Gender" class="col-sm-8"></div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">联系人</label>
            <div class="col-sm-8">
                <input id="contactsName" col="ContactsName" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">联系人电话</label>
            <div class="col-sm-8">
                <input id="contactsMobile" col="ContactsMobile" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">工作单位</label>
            <div class="col-sm-8">
                <textarea id="workUnit" col="WorkUnit" class="form-control"></textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">家庭住址</label>
            <div class="col-sm-8">
                <textarea id="address" col="Address" class="form-control"></textarea>
            </div>
        </div>
    </form>
</div>

<script type="text/javascript">
    var id = ys.request("id");
    $(function () {


        laydate.render({
            elem: '#birthday'
        });

        $("#occupationValue").ysRadioBox({
            data: ys.getJson(@Html.Raw(typeof(EnumOccupation).EnumToDictionaryString()))
        });

        $("#gender").ysRadioBox({
            data: ys.getJson(@Html.Raw(typeof(GenderTypeEnum).EnumToDictionaryString()))
        });

        $('#departmentId').ysComboBoxTree({ url: '@Url.Content("~/OrganizationManage/Department/GetDepartmentTreeListJsonNoAuthority")' });



        getForm();

        $("#form").validate({
            rules: {
                personName: { required: true }
            }
        });


    });

    function getForm() {




        if (id > 0) {
            ys.ajax({
                url: '@Url.Content("~/person/GetFormJson")' + '?id=' + id,
                type: "get",
                success: function (obj) {
                    if (obj.Tag == 1) {
                        var result = obj.Data;
                        //console.log(result);
                        //alert(result.DepartmentId)
                        //alert(result.DepartmentName)
                        $("#form").setWebControls(result);
                        //console.log(result);
                        $("#birthday").val(result.Birthday.substring(0,10))
                    }
                }
            });
        }

    }

    function saveForm(index) {
        if ($("#form").validate().form()) {

            var postData = $("#form").getWebControls({ Id: id });
            postData.DepartmentId = ys.getLastValue(postData.DepartmentId);
            //console.log(postData.DepartmentId)
            ys.ajax({
                url: '@Url.Content("~/person/SaveFormJson")',
                type: "post",
                data: postData,
                success: function (obj) {
                    if (obj.Tag == 1) {
                        ys.msgSuccess(obj.Message);
                        parent.searchGrid();
                        parent.layer.close(index);
                    }
                    else {
                        ys.msgError(obj.Message);
                    }
                }
            });
        }
    }
</script>
